package com.yixin.hospital.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yixin.hospital.common.ApiResult;
import com.yixin.hospital.common.Constant;
import com.yixin.hospital.entity.domain.Activity;
import com.yixin.hospital.entity.dto.req.activity.ActivityAddReqDTO;
import com.yixin.hospital.entity.dto.req.activity.ActivityEditReqDTO;
import com.yixin.hospital.service.ActivityService;
import com.yixin.hospital.mapper.ActivityMapper;
import com.yixin.hospital.utils.JwtUtil;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;

/**
* @author Administrator
* @description 针对表【activity(活动表)】的数据库操作Service实现
* @createDate 2024-10-09 16:12:24
*/
@Service
public class ActivityServiceImpl extends ServiceImpl<ActivityMapper, Activity>
    implements ActivityService{

    @Override
    public ApiResult<?> add(ActivityAddReqDTO activityAddReqDTO, HttpServletRequest request) {
        String userName = JwtUtil.getName(request.getHeader(Constant.AUTHORIZATION));
        Activity activity = new Activity();
        BeanUtils.copyProperties(activityAddReqDTO, activity);
        activity.setCreatedBy(userName);
        activity.setUpdatedBy(userName);
        this.save(activity);
        return ApiResult.success();
    }

    @Override
    public ApiResult<?> edit(ActivityEditReqDTO activityEditReqDTO, HttpServletRequest request) {
        String userName = JwtUtil.getName(request.getHeader(Constant.AUTHORIZATION));
        Activity activity = new Activity();
        BeanUtils.copyProperties(activityEditReqDTO, activity);
        activity.setUpdatedBy(userName);
        this.updateById(activity);
        return ApiResult.success();
    }

    @Override
    public ApiResult<?> removeActivity(int id) {
        this.removeById(id);
        return ApiResult.success();
    }
}




